package com.wunu.smartlock1.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.view.View.OnClickListener;
import com.wunu.smartlock1.R;
import com.wunu.smartlock1.adapter.AuthorizedRecordAdapter;
import com.wunu.smartlock1.model.AuthorizedRecordVo;
import android.widget.CheckBox;
import java.util.ArrayList;
import java.util.List;
import android.view.View;

/**
 * 开锁记录
 * Created by admin on 2018/4/21.
 */

public class LockRecordActivity extends AppCompatActivity {
    public static boolean isChecked = true;
    private CheckBox authorized;
    private CheckBox tempoary;
    AuthorizedRecordAdapter adapter;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.smartlock_activity_lockrecord);
        tempoary = (CheckBox) findViewById(R.id.tempoary);
        authorized = (CheckBox) findViewById(R.id.authorized);
        List<AuthorizedRecordVo> list = getMemberList(isChecked);
        if(isChecked) {
            authorized.setChecked(isChecked);
            tempoary.setChecked(false);
        }else{
            authorized.setChecked(false);
            tempoary.setChecked(true);
        }
        adapter = new AuthorizedRecordAdapter(LockRecordActivity.this, R.layout.smartlock_activity_lockrecord_item, list);
        ListView listView = (ListView) findViewById(R.id.recordListView);
        listView.setAdapter(adapter);

        authorized.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                isChecked = true;
                tempoary.setChecked(false);
                authorized.setChecked(true);

                List<AuthorizedRecordVo> list = getMemberList(isChecked);
                adapter =new AuthorizedRecordAdapter(LockRecordActivity.this, R.layout.smartlock_activity_lockrecord_item, list);
                ListView listView = (ListView) findViewById(R.id.recordListView);
                listView.setAdapter(adapter);
            }
        });

        tempoary.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                isChecked = false;
                tempoary.setChecked(true);
                authorized.setChecked(false);

                List<AuthorizedRecordVo> list = getMemberList(isChecked);
                adapter =new AuthorizedRecordAdapter(LockRecordActivity.this, R.layout.smartlock_activity_lockrecord_item, list);
                ListView listView = (ListView) findViewById(R.id.recordListView);
                listView.setAdapter(adapter);
            }
        });
}


    public List<AuthorizedRecordVo> getMemberList(boolean flag){
        List<AuthorizedRecordVo> list = new ArrayList<AuthorizedRecordVo>();
        if(flag){
            for(int i=0;i<20;i++){
                AuthorizedRecordVo obj = new AuthorizedRecordVo();
                obj.setAuthorizedCode("903269");
                obj.setAuthorizedName("柳岸花明");
                obj.setAuthorizedPicUrl(R.mipmap.member);
                obj.setLockStatus("开锁成功");
                obj.setLockTime("01-30 18:00");
                obj.setMemberType(0);
                list.add(obj);
            }
        }else{
            for(int i=0;i<20;i++){
                AuthorizedRecordVo obj = new AuthorizedRecordVo();
                obj.setAuthorizedCode("903269");
                obj.setAuthorizedName("爱恨交戈");
                obj.setAuthorizedPicUrl(R.mipmap.member);
                obj.setLockStatus("连接失败");
                obj.setLockTime("01-30 18:00");
                obj.setMemberType(1);
                list.add(obj);
            }
        }
        return list;
    }
}
